<?php

declare (strict_types = 1);

namespace app\store\controller\user;

use app\store\controller\Controller;
use app\store\service\user\Posts as PostsService;
use think\App;
use think\response\Json;

/**
 * 帖子记录类
 */
class Posts extends Controller
{
    public PostsService $postsService;
    public function __construct(App $app,PostsService $postsService)
    {
        parent::__construct($app);
        $this->postsService = $postsService;
    }

    public function index():Json
    {
      $params = $this->request->get();
      $this->validate(
          $params,
          [
              'page' => 'integer',
              'limit' => 'integer',
              'status|状态' => 'integer',
              //'search|用户搜索' => ''

          ]
      );
      $list = $this->postsService->getIndex($params);
      return $this->renderSuccess(compact('list'));
    }

    public function check():Json
    {
        $params = $this->request->post();
        $this->validate(
            $params,
            [
                'id' => 'require',
                'status' => 'require'  //1审核通过  -1拒绝
            ]
        );
        $res = $this->postsService->check($params);
        if(!$res){
            return $this->renderError('审核失败');
        }
        return $this->renderSuccess([],'审核成功');
    }
}
